<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.util.DateTime"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="com.is.control.UserControl"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.control.ParamClassControl"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.model.ParamStuyear"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.model.ParamCourse"%>
<%@page import="com.is.model.ParamClass"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript">
	$(function(){
		var block = $("#magic_block");
		if($(".active a").position()){
			block.css("top",$(".active a").position().top+10)
			.data("oriTop",$(".active a").position().top)
		}
		$(".nav ul li").find("a").hover(
			function(){
				var $this = $(this);
				var newTop = $this.position().top;
				block.stop().animate({
					top:newTop+10
				})
			},
			function(){
				block.stop().animate({
					top:block.data("oriTop")+10
				})
			}
		)
		var h = $(".right").height();
		$(".left").height(h);
		$(".update").click(function(){
			$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
		})
		$('img').error(function(){
			this.src = "/InterStu/resources/image/man.GIF";
		})
		/*公式*/
		var reg = /^\d*\.?\d*$/;
		$(".expression").bind("keyup",function(e){
			var currentSum = 0;
			for(var i = 0,j=0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					currentSum += $(".expression").eq(i).val()*1;
					j++;
				}
			}
			if(j == 3 && currentSum !=100){
				var temVal = $(this).val();
				$(".expression").val("");
				$(this).val(temVal);
			}
			currentSum-=$(this).val()*1;
			if(!reg.test($(this).val()) || $(this).val()*1 + currentSum >100){
				var tem = $(this).val().substring(0,$(this).val().length-1)
				$(this).val(tem);
			}
			if(($(this).val()+"").length<2 && $(this).val()!= "" && $(this).val()*1 === 0 && e.keyCode!=8 || $(this).val()== "."){
				 $(this).val("0.");
			}
		})
		.blur(function(){
			if($(this).val()*1<=0){
				$(this).val("");
			}
			var sum = 0;
			var j = 0;
			for(var i = 0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					j++;
					sum += $(".expression").eq(i).val()*1;
				}
			}
			if(j>1){
				for(var i = 0;i<$(".expression").size();i++){
					if($(".expression").eq(i).val() == "")
					$(".expression").eq(i).val(100 - sum);
				}
			}
		})
		$(".reset").click(function(e){
			$(".expression").val("");
		})
		$("[name='add_gs']").submit(function(e){
			var currentSum = 0;
			for(var i = 0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					currentSum += $(".expression").eq(i).val()*1;
				}
			}
			if(currentSum != 100){
				e.preventDefault();
			}
		})
	})
</script>
<title>留学生预科班</title>
</head>
<%
     	User cu =(User)session.getAttribute("user"); 
      //根据学期录入
      int stuyear = ParamUtil.getInt(request,"stuyear",ParamStuyearControl.getCurrentStuyearId());//设置默认参数为当前学年
 %>
<body>
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left"> 
	  <div class="infomation">
			<div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src = "<%=picUrl %>" />
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
		</div>  	   	  	
    	<div class="nav">
        	<ul>	
            	<li class="pa" id="magic_block"></li>
                <li><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li>
                <li class="active"><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li>
                <li><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li>
                <li><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li>
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li>
            </ul>
        </div>
    </div>
    <div class="right">
    	<div class="r1">
    	<table class="user tab">
    <tr>
    	<td>
    		<a href="/InterStu/pages/users/user_all.jsp">添加用户</a>
		</td>
		<td>
			<a class="current" href="/InterStu/pages/courseClass/set.jsp">课程分配</a>
		</td>
    </tr>
    </table>
    	<form>
    	<table class='table'>
    	<caption>请选择</caption>
    		<tr>
				<td>学期</td>
				<td>
				<select name="stuyear">
					<%
					      List<ParamStuyear> pss = ParamStuyearControl.getAllStuyear();
					      for(ParamStuyear ps:pss){
					      %>
					      <option value="<%=ps.getId() %>" <%if(stuyear==ps.getId()) out.print("selected"); %>><%=ps.getStuyear()%></option>
					      <%
					      }
					 %></select>
				</td>
				<td><input type="submit" value="查看"/></td>
    		</tr>
    	</table>
    	</form>
        </div>
        <div class="r2">
        <table class='table'>
        <caption>教师任课以及课时分配情况</caption>
	        <%
				         List<CourseClass> ccs = CourseClassControl.getAllCourseClassIdByUidAndStuyear(0,stuyear);
				         if(ccs.size()==0){
				        	 out.print("<tr><td>暂无</td></tr>");
				        	 
				         }else{
			%>
			<thead>
			 <tr>
			 <th>教师姓名</th>
			 <th>课程</th>
			 <th>班级</th>
			 <th>预计课时</th>
			 <th>实际课时(截止到<%=DateTime.SimpleDate() %>)</th>
			 <th>状态</th>
			 </tr>
			 </thead>
			 <tbody>
			 <%
               
               for(CourseClass cc:ccs){
               	%>
               	<tr>
               	<td><%=UserControl.getUserById(cc.getUid()).getName() %></td>
               	<td><%=ParamCourseControl.getCourseById(cc.getCourseId()).getCourseName() %></td>
               	<td><%=ParamClassControl.getClassName(cc.getClassId()) %></td>
               	<td><%=cc.getPrevTotalClass() %></td>
               	<td><%=cc.getRealTotalClass() %></td>
               	<td><%out.print((cc.getState()==1)?"成绩提交、不能修改":"正常");%></td>
               	</tr>
               	<%
               }
			 %>
			 </tbody>
		</table>
			 <%} %>
			 
			 <br/>
			
			<form action="deal.jsp" name='add_gs' method="post">
			<table class='table'>
			<caption>分配本学期教师任课情况（这个地方应实现同时填写多个）</caption>
			<tr><td>教师</td>
			<td>
			<select name="uid">
			<%
			     List<User> teas1 = UserControl.getAllUsersByRole("0");  //获取普通教师
				 List<User> teas2 = UserControl.getAllUsersByRole("1");  //获取管理员
				List<User> teas = new ArrayList<User>();
				teas.addAll(teas2);
				teas.addAll(teas1);
			    for(User tea:teas){
			%>
			<option value="<%=tea.getId() %>"><%=tea.getName() %></option>
			<%} %>
			</select>
			</td><td>课程</td><td><select name="courseId">
			<%
			       List<ParamCourse> pcs = ParamCourseControl.getAllCoursesByType(ParamStuyearControl.getCurrentStuyear().getTypeId()+"");
			       for(ParamCourse pc:pcs){
			 %>
			<option value="<%=pc.getId() %>"><%=pc.getCourseName() %></option>
			<%} %>
			</select></td>
			<td>班级</td>
			<td><select name="classId">
			<%
			       List<ParamClass> pcas = ParamClassControl.getParamClassesByStuyear(ParamStuyearControl.getCurrentStuyearId());
			       for(ParamClass pca:pcas){
			 %>
			<option value="<%=pca.getId() %>"><%=pca.getClassName() %></option>
			<%} %>
			</select></td>
			<td rowspan="2"><input type="submit" value="提交"/></td>
			</tr>
			<tr>
				<td>预计课时</td>
			<td><input type="text" name="prevTotalClass"/></td>
			<td>
				最终成绩分布
			</td>
			<td colspan="3">
				平时：<input class="expression" style="width:40px" type="text" name="daily"/>&nbsp;%，
				期中：<input class="expression" style="width:40px" type="text" name="mid"/>&nbsp;%，
				期末：<input class="expression" style="width:40px" type="text" name="final"/>&nbsp;% 
				&nbsp;<a href="javascript:void(0);" class="reset">[清空]</a>&nbsp;（输入所占最终成绩的比例）
			</td>
			</tr>
			</table>
			<br/>
			<p>
			<input type="button" value="返回课程设置" onclick="window.location.href='../paramCourse/course.jsp'"/></p>
			</form>
        </div>
    </div>
</div>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
</body>
</html>
